<?xml version="1.0" encoding="utf-8" ?> 
<sqlMap namespace="Area"
	xmlns="http://ibatis.apache.org/mapping" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<alias>
		<typeAlias alias="Area" type="Domain.Area" />
	</alias>

	<resultMaps>
		<resultMap id="FullResultMap" class="Area">
			<result property="ID" column="ID" dbType="Int"/>
			<result property="Name" column="Name" dbType="NVarChar"/>
			<result property="OrderID" column="OrderID" dbType="Int"/>
			<result property="HeadID" column="HeadID" dbType="Int"/>
			<result property="Level" column="Level" dbType="Int"/>
			<result property="Family" column="Family" dbType="NVarChar"/>
		</resultMap>
	</resultMaps>
	
	<statements>

		<select id="GetCount" resultClass="System.Int32">
			SELECT count(*) FROM [dbo].[Area]
		</select>
		
		<select id="GetCountByCondition" parameterClass="Hashtable" resultClass="System.Int32" extends="GetCount">
			WHERE $condition$
		</select>
		
		<select id="FindAll" resultClass="Area">
			SELECT * 
			FROM [dbo].[Area]
		</select>
		
		<select id="GetModel" parameterClass="Area" resultClass="Area" extends="FindAll">
			WHERE
				([Area].[ID] = #ID,dbType=Int#)
		</select>

		<insert id="Insert" parameterClass="Area">
			INSERT INTO [dbo].[Area] (
				
				[Name] , 
				[OrderID] , 
				[HeadID] , 
				[Level] , 
				[Family]
			) VALUES (
				
				 #Name,dbType=NVarChar# , 
				 #OrderID,dbType=Int# , 
				 #HeadID,dbType=Int# , 
				 #Level,dbType=Int# , 
				 #Family,dbType=NVarChar#
			)
		</insert>

		<update id="Update" parameterClass="Area">
			UPDATE [dbo].[Area] SET
				 [Name] = #Name,dbType=NVarChar#
				, [OrderID] = #OrderID,dbType=Int#
				, [HeadID] = #HeadID,dbType=Int#
				, [Level] = #Level,dbType=Int#
				, [Family] = #Family,dbType=NVarChar#
			WHERE
				([ID] = #ID,dbType=Int#)
		</update>

		<delete id="Delete" parameterClass="Area">
			DELETE FROM [dbo].[Area]
			WHERE
				([ID] = #ID,dbType=Int#)
		</delete>

		<select id="GetModelsByCondition" parameterClass="Hashtable" resultClass="Area">
			SELECT $columnNames$ FROM [dbo].[Area] where $condition$
		</select>
		
		<select id="GetModelsByConditionByPager" parameterClass="Hashtable" resultClass="Area">
			SELECT * FROM 
			(select $columnNames$,row_number() over(order by $orderBy$) as rno from [dbo].[Area] where $condition$) t 
			<![CDATA[
			where t.rno>#startNo# and t.rno<=#endNo#
			]]>
		</select>
		
	</statements>
</sqlMap>
